home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / full / nt / MSSql / I386 / sqlx86.exe / PTK / SAMPLES / OLEAUTO / GETNPV / TESTERR.SQL < prev   
Encoding:
Text File  |  1996-04-03  |  1.2 KB  |  48 lines

  1. /* Stored Procedure:    sp_testerr
  2. ** Description:        This sp connects back to SQL Server via an OA
  3. **            object outside SS.  The OA server retrieves a
  4. **            result set from a SS table and returns it back
  5. **            to this sp.
  6. */
  7.  
  8.  
  9. if exists (select * from sysobjects where id = object_id('dbo.sp_testerr') and sysstat & 0xf = 4)
  10.     drop proc sp_testerr
  11. go
  12.  
  13. create proc sp_testerr as
  14.     declare @pObj int, @hr int
  15.     declare @source varchar(30), @desc varchar(200)
  16.     declare @property varchar(30), @result int
  17.  
  18.     Print 'Test: testerr'
  19.     Print '--------------'
  20.  
  21.     /* Create a new OLE automation object */
  22.     exec @hr=sp_OACreate "GetNPV.CGetNPV", @pObj OUT
  23.     if @hr <> 0 goto Err
  24.  
  25.     Print ' '
  26.     exec @hr=sp_OAGetProperty @pObj, "MyProperty", @property OUT
  27.     if @hr <> 0 goto Err
  28.     select "MyProperty value"=@property
  29.  
  30.     Print ' '
  31.     Print 'Calling TestError method'
  32.     exec @hr=sp_OAMethod @pObj, "TestError", @result OUT
  33.     if @hr <> 0 goto Err
  34.  
  35.     select "Result"=@result
  36.     goto Done
  37.  
  38. Err:
  39.     Print ' '
  40.     Print '## ERROR ##'
  41.     exec sp_OAGetErrorInfo null, @source OUT, @desc OUT
  42.     select hr=convert(binary(4),@hr), source=@source, description=@desc
  43.     goto Done
  44.  
  45. Done:
  46.     exec sp_OADestroy @pObj
  47.     return @hr
  48. go